Skip to content

Add OpenCode Go usage API support - #2879

Merged
steipete merged 4 commits into
steipete:mainfrom
akshayprabhu200:codex/opencode-go-usage-api
Aug 19, 2026
Merged

Add OpenCode Go usage API support#2879
steipete merged 4 commits into
steipete:mainfrom
akshayprabhu200:codex/opencode-go-usage-api

Conversation

@akshayprabhu200

@akshayprabhu200 akshayprabhu200 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • use OpenCode Go's public GET /zen/go/v1/usage API for rolling, weekly, and monthly utilization
  • accept OPENCODE_API_KEY from CodexBar settings, provider config, or the environment
  • preserve local daily cost/model history while overlaying authoritative API windows
  • preserve an existing cookie-derived Zen balance independently of the API windows
  • retain the existing cookie-backed web path as a compatibility fallback

Why

OpenCode Go now exposes an authenticated public usage endpoint. CodexBar previously depended on local estimates or private web-session requests, even when a stable API key was available.

Behavior and compatibility

  • Automatic, unscoped discovery tries local history, then the public API, then the legacy web path.
  • Account-scoped discovery keeps the existing web/local ordering and uses the public API only as a fallback because an API key is not account-scoped.
  • API failures in automatic mode fall through to existing sources; cancellation still propagates.
  • Local cost and model history remain present when authoritative API utilization is overlaid.
  • When both credentials exist, API quota windows stay authoritative while the cookie source contributes only its Zen balance.

Proof

  • swift test --filter OpenCodeGo: 108 tests passed across 11 OpenCode Go suites on the initial implementation.
  • Focused post-review compatibility run: 16 tests passed, including a combined API-key + cookie case that asserts API percentages, retained local daily history, and retained Zen balance.
  • make check: passed after the review fix (formatting, SwiftLint, manifests, signing/package gates, and documentation links).
  • Request-contract tests verify the exact endpoint, Bearer authorization, all three returned windows, unauthorized responses, source routing, configuration normalization, and local-history preservation.

No personal usage data or credentials are included in this change. A live authenticated endpoint capture is not attached because no OPENCODE_API_KEY is available in this environment; all included network proof is deterministic request-contract coverage.

Closes anomalyco/opencode#31084

@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 12, 2026
@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed August 19, 2026, 8:51 AM ET / 12:51 UTC.

ClawSweeper review

What this changes

This PR adds an API-key source for OpenCode Go usage, overlays API quota windows onto local cost history, retains cookie-derived balance data, and updates provider documentation and tests.

Merge readiness

Blocked until real behavior proof from a real setup is added - 6 items remain

Current main does not support the OpenCode Go usage API, so this PR remains necessary, but it needs a scoped-source correction, maintainer product sponsorship for the new credential surface, and real authenticated proof before merge.

Priority: P2
Reviewed head: c27534e9ced0287c0a268f7f77b01da2c84f0577
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has focused coverage, but a scoped-ordering defect and missing real authenticated proof prevent merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR includes deterministic request and fallback tests but no redacted authenticated after-fix run against the real OpenCode Go API. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR includes deterministic request and fallback tests but no redacted authenticated after-fix run against the real OpenCode Go API. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 4 items Current main lacks this capability: Current main exposes only Auto and Web source modes for OpenCode Go; it has no API strategy or public usage endpoint.
Scoped ordering is bypassed: The local strategy invokes the API overlay whenever a key exists before checking cookie or workspace scope, despite scoped Auto ordering placing API after Web and Local.
Documented strategy conflict: The PR documents scoped Auto as Web → Local → API, while the local strategy can return local+API before the standalone API stage.
Findings 1 actionable finding [P1] Keep API overlays out of workspace-scoped Auto requests
Security None None.

How this fits together

CodexBar’s OpenCode Go provider turns local SQLite history, browser-cookie usage, and API data into one usage snapshot for the menu bar and CLI. Source ordering matters because cookie web usage is workspace-scoped while the new API key is not.

flowchart LR
A[Local SQLite history] --> D[OpenCode Go source selection]
B[Workspace cookie session] --> D
C[API key] --> D
D --> E[Quota and balance overlay]
E --> F[Usage snapshot]
F --> G[Menu bar and CLI]
Loading

Decision needed

Question Recommendation
Should CodexBar support the public OpenCode Go API only as an unscoped quota source, while preserving workspace-scoped cookie and local behavior? Sponsor unscoped API support: Accept the API as an unscoped source, require the scoped-ordering repair and authenticated proof, and retain current workspace behavior.

Why: This adds a new credential-backed provider capability, and tests cannot establish the desired product boundary for account-agnostic API data versus workspace-scoped usage.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR includes deterministic request and fallback tests but no redacted authenticated after-fix run against the real OpenCode Go API. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Keep API overlays out of workspace-scoped Auto requests (P1) - The API overlay runs immediately after a local read whenever an API key is present, before the code checks workspace scope. For a workspace override whose web auth is unavailable, this returns account-agnostic API quotas even though the documented scoped order places API last. Gate this overlay to unscoped Auto requests, or let the final API strategy own it, and cover the workspace-plus-local-history case.
  • Resolve merge risk (P2) - A workspace-scoped Auto request with local history and an API key can return account-agnostic API quotas before the documented fallback stage.
  • Resolve merge risk (P1) - The PR has deterministic tests but no redacted authenticated after-fix trace from the real OpenCode Go API.
  • Complete next step (P2) - A maintainer must first sponsor or decline the new account-agnostic API source; after sponsorship, the scoped-ordering fix and contributor-supplied proof are required.

Findings

  • [P1] Keep API overlays out of workspace-scoped Auto requests — Sources/CodexBarCore/Providers/OpenCodeGo/OpenCodeGoProviderDescriptor.swift:225-232
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Code and test delta production +186/-18, tests +139/-10 The provider feature spans credential settings, source routing, fetch logic, and focused coverage.
Files affected 13 files The change crosses provider implementation, settings UI, tests, and user documentation.

Merge-risk options

Maintainer options:

  1. Preserve scoped source boundaries (recommended)
    Skip API overlays for workspace-scoped Auto contexts and add a regression test covering workspace scope, local history, and an API key.
  2. Accept account-agnostic API data
    Merge the current behavior only if maintainers explicitly accept API quota windows replacing scoped workspace results in this path.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Skip API overlays for workspace-scoped Auto requests and add regression coverage for workspace scope, local history, and an API key.

Technical review

Best possible solution:

If maintainers sponsor the capability, restrict API overlays to unscoped usage, retain workspace-scoped Web → Local → API semantics, add regression coverage, and obtain a redacted real-account trace.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: use Auto mode with a workspace override, local history, and an API key after the web attempt cannot authenticate; the local strategy calls the API overlay before the separate API fallback.

Is this the best way to solve the issue?

No: the unscoped overlay approach is reasonable, but the same overlay must not run in a workspace-scoped request where the API key is account-agnostic.

Full review comments:

  • [P1] Keep API overlays out of workspace-scoped Auto requests — Sources/CodexBarCore/Providers/OpenCodeGo/OpenCodeGoProviderDescriptor.swift:225-232
    The API overlay runs immediately after a local read whenever an API key is present, before the code checks workspace scope. For a workspace override whose web auth is unavailable, this returns account-agnostic API quotas even though the documented scoped order places API last. Gate this overlay to unscoped Auto requests, or let the final API strategy own it, and cover the workspace-plus-local-history case.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 453174fe13ee.

Labels

Label justifications:

  • P2: The new provider path can mis-associate displayed quotas in a bounded scoped configuration, but it is not a core-runtime outage.
  • merge-risk: 🚨 compatibility: The PR changes automatic source ordering and can replace workspace-scoped results with API-key results.
  • merge-risk: 🚨 auth-provider: The PR adds API-key configuration, environment projection, and Bearer authorization for OpenCode Go.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR includes deterministic request and fallback tests but no redacted authenticated after-fix run against the real OpenCode Go API. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • steipete: Merged recent OpenCode Go confidence work and owns adjacent provider-architecture history. (role: recent area contributor; confidence: high; commits: ef1cb9257961; files: Sources/CodexBarCore/Providers/OpenCodeGo/OpenCodeGoProviderDescriptor.swift)
  • Aaron: Introduced the web-to-local authoritative usage overlay that this PR extends. (role: introduced authoritative overlay behavior; confidence: high; commits: cf7b74913366; files: Sources/CodexBarCore/Providers/OpenCodeGo/OpenCodeGoProviderDescriptor.swift)
  • Yuxin Qiao: Recent Zen-balance work overlaps the cookie balance preserved by this patch. (role: recent adjacent contributor; confidence: medium; commits: 8060110e146c; files: Sources/CodexBarCore/Providers/OpenCodeGo/OpenCodeGoUsageFetcher.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Resolve the workspace-scoped API-overlay defect and add regression coverage.
  • Post a redacted authenticated terminal or runtime trace showing API usage windows and the selected source.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-12T08:13:02.720Z sha 55cdcad :: needs real behavior proof before merge. :: [P2] Keep the cookie-sourced Zen balance after API overlay
  • reviewed 2026-08-12T08:30:43.558Z sha 801c317 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-12T08:51:21.530Z sha 801c317 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-12T09:07:37.419Z sha b839f54 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-13T03:09:37.314Z sha b839f54 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-13T03:54:48.839Z sha 2f42b83 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-13T04:21:11.659Z sha 2f42b83 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-19T04:55:11.659Z sha d467b54 :: needs real behavior proof before merge. :: none

@akshayprabhu200
akshayprabhu200 marked this pull request as ready for review August 12, 2026 08:10
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. label Aug 12, 2026
@akshayprabhu200

Copy link
Copy Markdown
Contributor Author

Fixed the failing macOS shard in signed commit b839f548.

The implementation intentionally adds OpenCode Go to the descriptor-derived API-key debug registry; the architecture gate's exact expected list had not been updated. The corrected gate now passes locally.

Verification:

  • swift test --filter ProviderArchitectureGatekeeperTests — 38 tests passed
  • swift test --filter OpenCodeGo — 108 tests passed

@clawsweeper re-review

— Akshay / Codex

@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@akshayprabhu200
akshayprabhu200 marked this pull request as draft August 13, 2026 03:05
@akshayprabhu200
akshayprabhu200 force-pushed the codex/opencode-go-usage-api branch from b839f54 to 2f42b83 Compare August 13, 2026 03:50
@akshayprabhu200

Copy link
Copy Markdown
Contributor Author

Rebased this draft PR onto current upstream main (208016687) with no conflicts or scope changes. The rewritten head 2f42b83b7 is signed and GitHub-verified.

The prior aggregate failure was draft policy rather than a provider regression: required macOS tests were deferred while the PR was draft, so the aggregate correctly reported incomplete. GitHub now reports the rebased branch mergeable.

— Akshay / Codex

@akshayprabhu200
akshayprabhu200 marked this pull request as ready for review August 13, 2026 04:18
@akshayprabhu200

Copy link
Copy Markdown
Contributor Author

Post-rebase verification is complete on head 2f42b83b7:

  • lint: passed
  • Linux x64: passed
  • Linux ARM64: passed
  • Linux musl: passed
  • macOS shard 1/2: passed
  • macOS shard 2/2: passed
  • aggregate CI: passed
  • GitGuardian: passed

GitHub reports the PR mergeable. ClawSweeper found no actionable implementation or security findings; its remaining gate is an authenticated OpenCode Go runtime trace, which requires contributor-provided account credentials and must be redacted before posting.

— Akshay / Codex

@akshayprabhu200
akshayprabhu200 force-pushed the codex/opencode-go-usage-api branch from 2f42b83 to d467b54 Compare August 19, 2026 04:50
@akshayprabhu200

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (a32989c75) in signed commits through d467b54df.

The integration preserves #2987’s estimated-confidence and manual-token behavior while adding the authenticated API overlay and retaining Zen balance. The original worktree’s unrelated local edits were not touched. SwiftFormat and git diff --check pass; affected production sources compile cleanly. Current-head CI is the authoritative full validation.

Tracking issue: #3065.

— Akshay / Codex

@steipete
steipete merged commit 05a7a44 into steipete:main Aug 19, 2026
9 checks passed
steipete added a commit that referenced this pull request Aug 19, 2026
@jpagh

jpagh commented Aug 19, 2026

Copy link
Copy Markdown

Glad to see this merged. Cookies weren't working for me. I pulled and built this branch and it's been working great. Thanks @akshayprabhu200 @steipete !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Public API for Go plan usage/limits

3 participants